package com.clkj.nangang.mvp.index.aboutme;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.clkj.nangang.R;
import com.clkj.nangang.mvp.adapter.ViewPagerNewsAdapter;
import com.clkj.nangang.mvp.base.BaseActivity;
import com.clkj.nangang.mvp.index.aboutme.homeservice.FragmentHomeService;

import java.util.ArrayList;
import java.util.List;

public class AboutMeActivity extends BaseActivity {

    private TabLayout tabNewsTitle;
    private ViewPager vpNewsPager;

    private ViewPagerNewsAdapter viewPagerNewsAdapter;
    private List<Fragment> fragmentList = new ArrayList<>();
    private List<String> mTitles = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_me);
        initTitle(null, null, "与我有关", true, null);
        initData();
        initView();
        assignView();
    }

    @Override
    public void initData() {
        fragmentList = new ArrayList<>();
        mTitles = new ArrayList<>();
        mTitles.add("居家服务");
        mTitles.add("招工信息");
        mTitles.add("办事指南");

        fragmentList.add(FragmentHomeService.newInstance("居家服务"));
        fragmentList.add(FragmentAboutme.newInstance("招工信息"));
        fragmentList.add(FragmentAboutme.newInstance("办事指南"));

    }

    @Override
    public void assignView() {

        //设置TabLayout的模式
        tabNewsTitle.setTabMode(TabLayout.MODE_FIXED);

        //viewpager加载adapter
        viewPagerNewsAdapter = new ViewPagerNewsAdapter(getSupportFragmentManager(), fragmentList, mTitles);
        vpNewsPager.setAdapter(viewPagerNewsAdapter);
        vpNewsPager.setOffscreenPageLimit(3);
        //TabLayout加载viewpager
        tabNewsTitle.setupWithViewPager(vpNewsPager);
    }

    public void initView() {
        tabNewsTitle = (TabLayout) findViewById(R.id.tab_news_title);
        vpNewsPager = (ViewPager) findViewById(R.id.vp_news_pager);
    }
}
